import _asyncToGenerator from '@babel/runtime/helpers/esm/asyncToGenerator';
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
import _typeof from '@babel/runtime/helpers/esm/typeof';
import { Button, Form, Modal, Steps } from 'antd';
import React, {
  Children,
  forwardRef,
  useCallback,
  useEffect,
  useImperativeHandle,
  useMemo,
  useRef,
  useState,
} from 'react';
import './index.css';
var _excluded = [
  'name',
  'title',
  'subTitle',
  'description',
  'icon',
  'status',
  'stepProps',
  'disabled',
];
function _regeneratorRuntime() {
  'use strict';
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime =
    function _regeneratorRuntime() {
      return exports;
    };
  var exports = {},
    Op = Object.prototype,
    hasOwn = Op.hasOwnProperty,
    defineProperty =
      Object.defineProperty ||
      function (obj, key, desc) {
        obj[key] = desc.value;
      },
    $Symbol = 'function' == typeof Symbol ? Symbol : {},
    iteratorSymbol = $Symbol.iterator || '@@iterator',
    asyncIteratorSymbol = $Symbol.asyncIterator || '@@asyncIterator',
    toStringTagSymbol = $Symbol.toStringTag || '@@toStringTag';
  function define(obj, key, value) {
    return (
      Object.defineProperty(obj, key, {
        value: value,
        enumerable: !0,
        configurable: !0,
        writable: !0,
      }),
      obj[key]
    );
  }
  try {
    define({}, '');
  } catch (err) {
    define = function define(obj, key, value) {
      return (obj[key] = value);
    };
  }
  function wrap(innerFn, outerFn, self, tryLocsList) {
    var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
      generator = Object.create(protoGenerator.prototype),
      context = new Context(tryLocsList || []);
    return (
      defineProperty(generator, '_invoke', { value: makeInvokeMethod(innerFn, self, context) }),
      generator
    );
  }
  function tryCatch(fn, obj, arg) {
    try {
      return { type: 'normal', arg: fn.call(obj, arg) };
    } catch (err) {
      return { type: 'throw', arg: err };
    }
  }
  exports.wrap = wrap;
  var ContinueSentinel = {};
  function Generator() {}
  function GeneratorFunction() {}
  function GeneratorFunctionPrototype() {}
  var IteratorPrototype = {};
  define(IteratorPrototype, iteratorSymbol, function () {
    return this;
  });
  var getProto = Object.getPrototypeOf,
    NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  NativeIteratorPrototype &&
    NativeIteratorPrototype !== Op &&
    hasOwn.call(NativeIteratorPrototype, iteratorSymbol) &&
    (IteratorPrototype = NativeIteratorPrototype);
  var Gp =
    (GeneratorFunctionPrototype.prototype =
    Generator.prototype =
      Object.create(IteratorPrototype));
  function defineIteratorMethods(prototype) {
    ['next', 'throw', 'return'].forEach(function (method) {
      define(prototype, method, function (arg) {
        return this._invoke(method, arg);
      });
    });
  }
  function AsyncIterator(generator, PromiseImpl) {
    function invoke(method, arg, resolve, reject) {
      var record = tryCatch(generator[method], generator, arg);
      if ('throw' !== record.type) {
        var result = record.arg,
          value = result.value;
        return value && 'object' == _typeof(value) && hasOwn.call(value, '__await')
          ? PromiseImpl.resolve(value.__await).then(
              function (value) {
                invoke('next', value, resolve, reject);
              },
              function (err) {
                invoke('throw', err, resolve, reject);
              },
            )
          : PromiseImpl.resolve(value).then(
              function (unwrapped) {
                (result.value = unwrapped), resolve(result);
              },
              function (error) {
                return invoke('throw', error, resolve, reject);
              },
            );
      }
      reject(record.arg);
    }
    var previousPromise;
    defineProperty(this, '_invoke', {
      value: function value(method, arg) {
        function callInvokeWithMethodAndArg() {
          return new PromiseImpl(function (resolve, reject) {
            invoke(method, arg, resolve, reject);
          });
        }
        return (previousPromise = previousPromise
          ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg)
          : callInvokeWithMethodAndArg());
      },
    });
  }
  function makeInvokeMethod(innerFn, self, context) {
    var state = 'suspendedStart';
    return function (method, arg) {
      if ('executing' === state) throw new Error('Generator is already running');
      if ('completed' === state) {
        if ('throw' === method) throw arg;
        return { value: void 0, done: !0 };
      }
      for (context.method = method, context.arg = arg; ; ) {
        var delegate = context.delegate;
        if (delegate) {
          var delegateResult = maybeInvokeDelegate(delegate, context);
          if (delegateResult) {
            if (delegateResult === ContinueSentinel) continue;
            return delegateResult;
          }
        }
        if ('next' === context.method) context.sent = context._sent = context.arg;
        else if ('throw' === context.method) {
          if ('suspendedStart' === state) throw ((state = 'completed'), context.arg);
          context.dispatchException(context.arg);
        } else 'return' === context.method && context.abrupt('return', context.arg);
        state = 'executing';
        var record = tryCatch(innerFn, self, context);
        if ('normal' === record.type) {
          if (
            ((state = context.done ? 'completed' : 'suspendedYield'),
            record.arg === ContinueSentinel)
          )
            continue;
          return { value: record.arg, done: context.done };
        }
        'throw' === record.type &&
          ((state = 'completed'), (context.method = 'throw'), (context.arg = record.arg));
      }
    };
  }
  function maybeInvokeDelegate(delegate, context) {
    var methodName = context.method,
      method = delegate.iterator[methodName];
    if (undefined === method)
      return (
        (context.delegate = null),
        ('throw' === methodName &&
          delegate.iterator.return &&
          ((context.method = 'return'),
          (context.arg = undefined),
          maybeInvokeDelegate(delegate, context),
          'throw' === context.method)) ||
          ('return' !== methodName &&
            ((context.method = 'throw'),
            (context.arg = new TypeError(
              "The iterator does not provide a '" + methodName + "' method",
            )))),
        ContinueSentinel
      );
    var record = tryCatch(method, delegate.iterator, context.arg);
    if ('throw' === record.type)
      return (
        (context.method = 'throw'),
        (context.arg = record.arg),
        (context.delegate = null),
        ContinueSentinel
      );
    var info = record.arg;
    return info
      ? info.done
        ? ((context[delegate.resultName] = info.value),
          (context.next = delegate.nextLoc),
          'return' !== context.method && ((context.method = 'next'), (context.arg = undefined)),
          (context.delegate = null),
          ContinueSentinel)
        : info
      : ((context.method = 'throw'),
        (context.arg = new TypeError('iterator result is not an object')),
        (context.delegate = null),
        ContinueSentinel);
  }
  function pushTryEntry(locs) {
    var entry = { tryLoc: locs[0] };
    1 in locs && (entry.catchLoc = locs[1]),
      2 in locs && ((entry.finallyLoc = locs[2]), (entry.afterLoc = locs[3])),
      this.tryEntries.push(entry);
  }
  function resetTryEntry(entry) {
    var record = entry.completion || {};
    (record.type = 'normal'), delete record.arg, (entry.completion = record);
  }
  function Context(tryLocsList) {
    (this.tryEntries = [{ tryLoc: 'root' }]),
      tryLocsList.forEach(pushTryEntry, this),
      this.reset(!0);
  }
  function values(iterable) {
    if (iterable || '' === iterable) {
      var iteratorMethod = iterable[iteratorSymbol];
      if (iteratorMethod) return iteratorMethod.call(iterable);
      if ('function' == typeof iterable.next) return iterable;
      if (!isNaN(iterable.length)) {
        var i = -1,
          next = function next() {
            for (; ++i < iterable.length; )
              if (hasOwn.call(iterable, i))
                return (next.value = iterable[i]), (next.done = !1), next;
            return (next.value = undefined), (next.done = !0), next;
          };
        return (next.next = next);
      }
    }
    throw new TypeError(_typeof(iterable) + ' is not iterable');
  }
  return (
    (GeneratorFunction.prototype = GeneratorFunctionPrototype),
    defineProperty(Gp, 'constructor', { value: GeneratorFunctionPrototype, configurable: !0 }),
    defineProperty(GeneratorFunctionPrototype, 'constructor', {
      value: GeneratorFunction,
      configurable: !0,
    }),
    (GeneratorFunction.displayName = define(
      GeneratorFunctionPrototype,
      toStringTagSymbol,
      'GeneratorFunction',
    )),
    (exports.isGeneratorFunction = function (genFun) {
      var ctor = 'function' == typeof genFun && genFun.constructor;
      return (
        !!ctor &&
        (ctor === GeneratorFunction || 'GeneratorFunction' === (ctor.displayName || ctor.name))
      );
    }),
    (exports.mark = function (genFun) {
      return (
        Object.setPrototypeOf
          ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype)
          : ((genFun.__proto__ = GeneratorFunctionPrototype),
            define(genFun, toStringTagSymbol, 'GeneratorFunction')),
        (genFun.prototype = Object.create(Gp)),
        genFun
      );
    }),
    (exports.awrap = function (arg) {
      return { __await: arg };
    }),
    defineIteratorMethods(AsyncIterator.prototype),
    define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
      return this;
    }),
    (exports.AsyncIterator = AsyncIterator),
    (exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
      void 0 === PromiseImpl && (PromiseImpl = Promise);
      var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
      return exports.isGeneratorFunction(outerFn)
        ? iter
        : iter.next().then(function (result) {
            return result.done ? result.value : iter.next();
          });
    }),
    defineIteratorMethods(Gp),
    define(Gp, toStringTagSymbol, 'Generator'),
    define(Gp, iteratorSymbol, function () {
      return this;
    }),
    define(Gp, 'toString', function () {
      return '[object Generator]';
    }),
    (exports.keys = function (val) {
      var object = Object(val),
        keys = [];
      for (var key in object) keys.push(key);
      return (
        keys.reverse(),
        function next() {
          for (; keys.length; ) {
            var key = keys.pop();
            if (key in object) return (next.value = key), (next.done = !1), next;
          }
          return (next.done = !0), next;
        }
      );
    }),
    (exports.values = values),
    (Context.prototype = {
      constructor: Context,
      reset: function reset(skipTempReset) {
        if (
          ((this.prev = 0),
          (this.next = 0),
          (this.sent = this._sent = undefined),
          (this.done = !1),
          (this.delegate = null),
          (this.method = 'next'),
          (this.arg = undefined),
          this.tryEntries.forEach(resetTryEntry),
          !skipTempReset)
        )
          for (var name in this)
            't' === name.charAt(0) &&
              hasOwn.call(this, name) &&
              !isNaN(+name.slice(1)) &&
              (this[name] = undefined);
      },
      stop: function stop() {
        this.done = !0;
        var rootRecord = this.tryEntries[0].completion;
        if ('throw' === rootRecord.type) throw rootRecord.arg;
        return this.rval;
      },
      dispatchException: function dispatchException(exception) {
        if (this.done) throw exception;
        var context = this;
        function handle(loc, caught) {
          return (
            (record.type = 'throw'),
            (record.arg = exception),
            (context.next = loc),
            caught && ((context.method = 'next'), (context.arg = undefined)),
            !!caught
          );
        }
        for (var i = this.tryEntries.length - 1; i >= 0; --i) {
          var entry = this.tryEntries[i],
            record = entry.completion;
          if ('root' === entry.tryLoc) return handle('end');
          if (entry.tryLoc <= this.prev) {
            var hasCatch = hasOwn.call(entry, 'catchLoc'),
              hasFinally = hasOwn.call(entry, 'finallyLoc');
            if (hasCatch && hasFinally) {
              if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
              if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
            } else if (hasCatch) {
              if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
            } else {
              if (!hasFinally) throw new Error('try statement without catch or finally');
              if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
            }
          }
        }
      },
      abrupt: function abrupt(type, arg) {
        for (var i = this.tryEntries.length - 1; i >= 0; --i) {
          var entry = this.tryEntries[i];
          if (
            entry.tryLoc <= this.prev &&
            hasOwn.call(entry, 'finallyLoc') &&
            this.prev < entry.finallyLoc
          ) {
            var finallyEntry = entry;
            break;
          }
        }
        finallyEntry &&
          ('break' === type || 'continue' === type) &&
          finallyEntry.tryLoc <= arg &&
          arg <= finallyEntry.finallyLoc &&
          (finallyEntry = null);
        var record = finallyEntry ? finallyEntry.completion : {};
        return (
          (record.type = type),
          (record.arg = arg),
          finallyEntry
            ? ((this.method = 'next'), (this.next = finallyEntry.finallyLoc), ContinueSentinel)
            : this.complete(record)
        );
      },
      complete: function complete(record, afterLoc) {
        if ('throw' === record.type) throw record.arg;
        return (
          'break' === record.type || 'continue' === record.type
            ? (this.next = record.arg)
            : 'return' === record.type
            ? ((this.rval = this.arg = record.arg), (this.method = 'return'), (this.next = 'end'))
            : 'normal' === record.type && afterLoc && (this.next = afterLoc),
          ContinueSentinel
        );
      },
      finish: function finish(finallyLoc) {
        for (var i = this.tryEntries.length - 1; i >= 0; --i) {
          var entry = this.tryEntries[i];
          if (entry.finallyLoc === finallyLoc)
            return (
              this.complete(entry.completion, entry.afterLoc),
              resetTryEntry(entry),
              ContinueSentinel
            );
        }
      },
      catch: function _catch(tryLoc) {
        for (var i = this.tryEntries.length - 1; i >= 0; --i) {
          var entry = this.tryEntries[i];
          if (entry.tryLoc === tryLoc) {
            var record = entry.completion;
            if ('throw' === record.type) {
              var thrown = record.arg;
              resetTryEntry(entry);
            }
            return thrown;
          }
        }
        throw new Error('illegal catch attempt');
      },
      delegateYield: function delegateYield(iterable, resultName, nextLoc) {
        return (
          (this.delegate = {
            iterator: values(iterable),
            resultName: resultName,
            nextLoc: nextLoc,
          }),
          'next' === this.method && (this.arg = undefined),
          ContinueSentinel
        );
      },
    }),
    exports
  );
}
var Step = Steps.Step;
var StepsForm = function StepsForm(_ref, ref) {
  var currentProp = _ref.current,
    formRefProp = _ref.formRef,
    style = _ref.style,
    onNext = _ref.onNext,
    onPrev = _ref.onPrev,
    onCancel = _ref.onCancel,
    onSave = _ref.onSave,
    onSubmit = _ref.onSubmit,
    onStepChange = _ref.onStepChange,
    onChange = _ref.onChange,
    onFormChange = _ref.onFormChange,
    onFormFinish = _ref.onFormFinish,
    children = _ref.children,
    footerRender = _ref.footerRender,
    buttonConfig = _ref.buttonConfig;
  var activeContentRef = useRef(null);
  var containerRef = useRef(null);
  var valuesRef = useRef({});
  var formRef = useRef();
  var _useState = useState(currentProp !== undefined ? currentProp : 0),
    _useState2 = _slicedToArray(_useState, 2),
    current = _useState2[0],
    setCurrent = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    submitting = _useState4[0],
    setSubmitting = _useState4[1];
  var stepLength = useMemo(
    function () {
      var result = 0;
      Children.forEach(children, function (child) {
        if (!child.props.virtual) result += 1;
      });
      return result;
    },
    [children],
  );
  var getNameByStep = useCallback(
    function (step) {
      var child = React.Children.toArray(children)[step];
      return child.props.name;
    },
    [children],
  );
  useEffect(
    function () {
      if (currentProp !== undefined && currentProp !== current) setCurrent(Number(currentProp));
    },
    [currentProp, current],
  );
  var go = useCallback(
    function (step, options) {
      var _containerRef$current;
      var rect =
        (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0
          ? void 0
          : _containerRef$current.getBoundingClientRect();
      if ((rect === null || rect === void 0 ? void 0 : rect.top) !== undefined)
        window.scrollTo(0, rect === null || rect === void 0 ? void 0 : rect.top);
      var formName = getNameByStep(current);
      var currentValues = valuesRef.current[formName];
      onChange === null || onChange === void 0
        ? void 0
        : onChange(step, {
            current: current,
            currentValues: currentValues,
            values: valuesRef.current,
            action: options.action,
          });
      // 受控模式下，由外部切换变更
      if (currentProp === undefined) setCurrent(step);
    },
    [current, currentProp, getNameByStep],
  );
  var isFieldsChanged = useCallback(function () {
    var _formRef$current;
    if (formRef.current)
      return (_formRef$current = formRef.current) === null || _formRef$current === void 0
        ? void 0
        : _formRef$current.isFieldsTouched();
    return false;
  }, []);
  var innerSubmit = useCallback(
    function (options) {
      if (formRef.current) {
        var _formRef$current2;
        setSubmitting(true);
        return (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0
          ? void 0
          : _formRef$current2
              .validateFields()
              .then(
                /*#__PURE__*/ (function () {
                  var _ref2 = _asyncToGenerator(
                    /*#__PURE__*/ _regeneratorRuntime().mark(function _callee(vals) {
                      var _formRef$current3, _activeContentRef$cur;
                      var formName, data;
                      return _regeneratorRuntime().wrap(function _callee$(_context) {
                        while (1)
                          switch ((_context.prev = _context.next)) {
                            case 0:
                              (_formRef$current3 = formRef.current) === null ||
                              _formRef$current3 === void 0
                                ? void 0
                                : _formRef$current3.submit();
                              formName = getNameByStep(current);
                              valuesRef.current[formName] = vals;
                              if (
                                !((_activeContentRef$cur = activeContentRef.current) === null ||
                                _activeContentRef$cur === void 0
                                  ? void 0
                                  : _activeContentRef$cur.submit)
                              ) {
                                _context.next = 11;
                                break;
                              }
                              _context.next = 6;
                              return activeContentRef.current.submit(vals, {
                                current: current,
                                values: valuesRef.current,
                                action:
                                  options === null || options === void 0 ? void 0 : options.action,
                              });
                            case 6:
                              data = _context.sent;
                              setSubmitting(false);
                              return _context.abrupt('return', data);
                            case 11:
                              setSubmitting(false);
                            case 12:
                              return _context.abrupt('return', vals);
                            case 13:
                            case 'end':
                              return _context.stop();
                          }
                      }, _callee);
                    }),
                  );
                  return function (_x) {
                    return _ref2.apply(this, arguments);
                  };
                })(),
              )
              .catch(function (err) {
                setSubmitting(false);
                var errorFields = err.errorFields;
                if (errorFields === null || errorFields === void 0 ? void 0 : errorFields.length) {
                  var _formRef$current4;
                  var name = errorFields[0].name;
                  (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0
                    ? void 0
                    : _formRef$current4.scrollToField(name, {
                        block: 'start',
                      });
                }
                throw err;
              });
      }
      return Promise.reject(null);
    },
    [current],
  );
  useImperativeHandle(
    ref,
    function () {
      return {
        submit: innerSubmit,
        formRef: formRef,
        valuesRef: valuesRef,
        contentRef: activeContentRef,
      };
    },
    [innerSubmit],
  );
  var goPrev = useCallback(
    function () {
      var exeute = function exeute() {
        var cb = function cb() {
          go(current - 1, {
            action: 'prev',
          });
        };
        if (!onPrev) return cb();
        var res = onPrev === null || onPrev === void 0 ? void 0 : onPrev();
        if (
          (res === null || res === void 0 ? void 0 : res.then) &&
          typeof (res === null || res === void 0 ? void 0 : res.then) === 'function'
        ) {
          res.then(function (success) {
            if (success !== false) cb();
          });
        } else {
          cb();
        }
      };
      if (isFieldsChanged()) {
        Modal.confirm({
          title: '温馨提示',
          content: '表单数据已变更，请确认是否返回上一步',
          onOk: exeute,
          okText: '继续',
        });
      } else {
        exeute();
      }
    },
    [isFieldsChanged, go, current],
  );
  var goNext = useCallback(
    function () {
      var cb = function cb() {
        go(current + 1, {
          action: 'next',
        });
      };
      innerSubmit({
        action: 'next',
      }).then(function (vals) {
        var res =
          onNext === null || onNext === void 0
            ? void 0
            : onNext(vals, {
                current: current,
                values: valuesRef.current,
              });
        if (
          (res === null || res === void 0 ? void 0 : res.then) &&
          typeof (res === null || res === void 0 ? void 0 : res.then) === 'function'
        ) {
          res.then(function (success) {
            if (success !== false) cb();
          });
        } else {
          cb();
        }
      });
    },
    [go, current, innerSubmit],
  );
  var save = useCallback(
    function () {
      innerSubmit({
        action: 'save',
      }).then(function (vals) {
        onSave === null || onSave === void 0
          ? void 0
          : onSave(vals, {
              current: current,
              values: valuesRef.current,
            });
      });
    },
    [current, innerSubmit],
  );
  var submit = useCallback(
    function () {
      innerSubmit({
        action: 'submit',
      }).then(function (vals) {
        onSubmit === null || onSubmit === void 0
          ? void 0
          : onSubmit(vals, {
              current: current,
              values: valuesRef.current,
            });
      });
    },
    [current, innerSubmit],
  );
  var cancel = useCallback(function () {
    onCancel === null || onCancel === void 0 ? void 0 : onCancel();
  }, []);
  var changeStep = useCallback(
    function (step) {
      var cb = function cb() {
        onStepChange === null || onStepChange === void 0 ? void 0 : onStepChange(step);
        go(step, {
          action: 'changestep',
        });
      };
      if (isFieldsChanged()) {
        Modal.confirm({
          title: '温馨提示',
          content: '表单数据已变更，请确认是否继续跳转其他步骤',
          onOk: function onOk() {
            cb();
          },
          okText: '跳转',
        });
      } else {
        cb();
      }
    },
    [go],
  );
  var btns = useMemo(
    function () {
      var _buttonConfig$cancel,
        _buttonConfig$cancel$,
        _buttonConfig$cancel2,
        _buttonConfig$prev,
        _buttonConfig$prev$te,
        _buttonConfig$prev2,
        _buttonConfig$save,
        _buttonConfig$save2,
        _buttonConfig$save3,
        _buttonConfig$save$te,
        _buttonConfig$save4,
        _buttonConfig$next,
        _buttonConfig$next$te,
        _buttonConfig$next2,
        _buttonConfig$submit,
        _buttonConfig$submit2,
        _buttonConfig$submit3,
        _buttonConfig$submit$,
        _buttonConfig$submit4;
      var btnsMap = {
        cancel: {
          key: 'cancel',
          condition: true,
          btn: /*#__PURE__*/ React.createElement(
            Button,
            _objectSpread(
              _objectSpread(
                {
                  loading: submitting,
                },
                buttonConfig === null || buttonConfig === void 0
                  ? void 0
                  : (_buttonConfig$cancel = buttonConfig.cancel) === null ||
                    _buttonConfig$cancel === void 0
                  ? void 0
                  : _buttonConfig$cancel.props,
              ),
              {},
              {
                className: 'szzj-antd-step-forms-footer-button',
                onClick: cancel,
                key: 'cancel',
              },
            ),
            (_buttonConfig$cancel$ =
              buttonConfig === null || buttonConfig === void 0
                ? void 0
                : (_buttonConfig$cancel2 = buttonConfig.cancel) === null ||
                  _buttonConfig$cancel2 === void 0
                ? void 0
                : _buttonConfig$cancel2.text) !== null && _buttonConfig$cancel$ !== void 0
              ? _buttonConfig$cancel$
              : '取消',
          ),
        },
        prev: {
          key: 'prev',
          condition: current > 0,
          btn: /*#__PURE__*/ React.createElement(
            Button,
            _objectSpread(
              _objectSpread(
                {
                  loading: submitting,
                },
                buttonConfig === null || buttonConfig === void 0
                  ? void 0
                  : (_buttonConfig$prev = buttonConfig.prev) === null ||
                    _buttonConfig$prev === void 0
                  ? void 0
                  : _buttonConfig$prev.props,
              ),
              {},
              {
                className: 'szzj-antd-step-forms-footer-button',
                onClick: goPrev,
                key: 'prev',
              },
            ),
            (_buttonConfig$prev$te =
              buttonConfig === null || buttonConfig === void 0
                ? void 0
                : (_buttonConfig$prev2 = buttonConfig.prev) === null ||
                  _buttonConfig$prev2 === void 0
                ? void 0
                : _buttonConfig$prev2.text) !== null && _buttonConfig$prev$te !== void 0
              ? _buttonConfig$prev$te
              : '上一步',
          ),
        },
        save: {
          key: 'save',
          condition:
            (buttonConfig === null || buttonConfig === void 0
              ? void 0
              : (_buttonConfig$save = buttonConfig.save) === null || _buttonConfig$save === void 0
              ? void 0
              : _buttonConfig$save.enable) !== undefined
              ? buttonConfig === null || buttonConfig === void 0
                ? void 0
                : (_buttonConfig$save2 = buttonConfig.save) === null ||
                  _buttonConfig$save2 === void 0
                ? void 0
                : _buttonConfig$save2.enable
              : true,
          btn: /*#__PURE__*/ React.createElement(
            Button,
            _objectSpread(
              _objectSpread(
                {
                  loading: submitting,
                },
                buttonConfig === null || buttonConfig === void 0
                  ? void 0
                  : (_buttonConfig$save3 = buttonConfig.save) === null ||
                    _buttonConfig$save3 === void 0
                  ? void 0
                  : _buttonConfig$save3.props,
              ),
              {},
              {
                className: 'szzj-antd-step-forms-footer-button',
                onClick: save,
                key: 'save',
              },
            ),
            (_buttonConfig$save$te =
              buttonConfig === null || buttonConfig === void 0
                ? void 0
                : (_buttonConfig$save4 = buttonConfig.save) === null ||
                  _buttonConfig$save4 === void 0
                ? void 0
                : _buttonConfig$save4.text) !== null && _buttonConfig$save$te !== void 0
              ? _buttonConfig$save$te
              : '保存',
          ),
        },
        next: {
          key: 'next',
          condition: current < stepLength - 1,
          btn: /*#__PURE__*/ React.createElement(
            Button,
            _objectSpread(
              _objectSpread(
                {
                  type: 'primary',
                  loading: submitting,
                },
                buttonConfig === null || buttonConfig === void 0
                  ? void 0
                  : (_buttonConfig$next = buttonConfig.next) === null ||
                    _buttonConfig$next === void 0
                  ? void 0
                  : _buttonConfig$next.props,
              ),
              {},
              {
                className: 'szzj-antd-step-forms-footer-button',
                onClick: goNext,
                key: 'next',
              },
            ),
            (_buttonConfig$next$te =
              buttonConfig === null || buttonConfig === void 0
                ? void 0
                : (_buttonConfig$next2 = buttonConfig.next) === null ||
                  _buttonConfig$next2 === void 0
                ? void 0
                : _buttonConfig$next2.text) !== null && _buttonConfig$next$te !== void 0
              ? _buttonConfig$next$te
              : '下一步',
          ),
        },
        submit: {
          key: 'submit',
          condition:
            ((buttonConfig === null || buttonConfig === void 0
              ? void 0
              : (_buttonConfig$submit = buttonConfig.submit) === null ||
                _buttonConfig$submit === void 0
              ? void 0
              : _buttonConfig$submit.enable) !== undefined
              ? buttonConfig === null || buttonConfig === void 0
                ? void 0
                : (_buttonConfig$submit2 = buttonConfig.submit) === null ||
                  _buttonConfig$submit2 === void 0
                ? void 0
                : _buttonConfig$submit2.enable
              : true) && current === stepLength - 1,
          btn: /*#__PURE__*/ React.createElement(
            Button,
            _objectSpread(
              _objectSpread(
                {
                  type: 'primary',
                  loading: submitting,
                },
                buttonConfig === null || buttonConfig === void 0
                  ? void 0
                  : (_buttonConfig$submit3 = buttonConfig.submit) === null ||
                    _buttonConfig$submit3 === void 0
                  ? void 0
                  : _buttonConfig$submit3.props,
              ),
              {},
              {
                className: 'szzj-antd-step-forms-footer-button',
                onClick: submit,
                key: 'submit',
              },
            ),
            (_buttonConfig$submit$ =
              buttonConfig === null || buttonConfig === void 0
                ? void 0
                : (_buttonConfig$submit4 = buttonConfig.submit) === null ||
                  _buttonConfig$submit4 === void 0
                ? void 0
                : _buttonConfig$submit4.text) !== null && _buttonConfig$submit$ !== void 0
              ? _buttonConfig$submit$
              : '提交',
          ),
        },
      };
      var activedBtns = Object.keys(btnsMap)
        .filter(function (key) {
          return btnsMap[key].condition;
        })
        .sort(function (aKey, bKey) {
          var _buttonConfig$aKey, _buttonConfig$bKey;
          var aOrder =
            buttonConfig === null || buttonConfig === void 0
              ? void 0
              : (_buttonConfig$aKey = buttonConfig[aKey]) === null || _buttonConfig$aKey === void 0
              ? void 0
              : _buttonConfig$aKey.order;
          var bOrder =
            buttonConfig === null || buttonConfig === void 0
              ? void 0
              : (_buttonConfig$bKey = buttonConfig[bKey]) === null || _buttonConfig$bKey === void 0
              ? void 0
              : _buttonConfig$bKey.order;
          if (aOrder !== undefined && bOrder !== undefined) {
            return bOrder - aOrder;
          }
          return 1;
        })
        .map(function (key) {
          return btnsMap[key].btn;
        });
      return footerRender
        ? footerRender({
            current: current,
            buttons: activedBtns,
          })
        : activedBtns;
    },
    [
      footerRender,
      buttonConfig,
      current,
      children,
      goPrev,
      goNext,
      save,
      submit,
      cancel,
      submitting,
    ],
  );
  return /*#__PURE__*/ React.createElement(
    'div',
    {
      className: 'szzj-antd-step-forms',
      style: style,
      ref: containerRef,
    },
    /*#__PURE__*/ React.createElement(
      'div',
      {
        className: 'szzj-antd-step-forms-steps',
      },
      /*#__PURE__*/ React.createElement(
        Steps,
        {
          current: current,
          onChange: changeStep,
        },
        Children.map(children, function (item) {
          var _item$props = item.props,
            name = _item$props.name,
            title = _item$props.title,
            subTitle = _item$props.subTitle,
            description = _item$props.description,
            icon = _item$props.icon,
            status = _item$props.status,
            disabled = _item$props.disabled,
            stepProps = _item$props.stepProps;
          return /*#__PURE__*/ React.createElement(
            Step,
            _objectSpread(
              {
                key: name,
                title: title,
                subTitle: subTitle,
                description: description,
                icon: icon,
                status: status,
                disabled: disabled,
              },
              stepProps,
            ),
          );
        }),
      ),
    ),
    /*#__PURE__*/ React.createElement(
      'div',
      {
        className: 'szzj-antd-step-forms-content',
      },
      /*#__PURE__*/ React.createElement(
        Form.Provider,
        {
          onFormChange: onFormChange,
          onFormFinish: onFormFinish,
        },
        Children.map(children, function (item, index) {
          var _item$props2 = item.props,
            name = _item$props2.name,
            title = _item$props2.title,
            subTitle = _item$props2.subTitle,
            description = _item$props2.description,
            icon = _item$props2.icon,
            status = _item$props2.status,
            stepProps = _item$props2.stepProps,
            disabled = _item$props2.disabled,
            rest = _objectWithoutProperties(_item$props2, _excluded);
          return /*#__PURE__*/ React.createElement(
            Form,
            _objectSpread(
              {
                key: name,
                name: name,
              },
              rest,
            ),
            index === current &&
              /*#__PURE__*/
              /**
               * @todo 每次必刷新，性能不好，但能简化编程
               */
              React.createElement(
                Form.Item,
                {
                  noStyle: true,
                  shouldUpdate: true,
                },
                function (stepForm) {
                  var _item$props$children, _item$props$children$;
                  // @ts-ignore
                  formRef.current = stepForm;
                  // @ts-ignore
                  if (formRefProp) formRefProp.current = stepForm;
                  return /*#__PURE__*/ React.cloneElement(item.props.children, {
                    form: stepForm,
                    current: current,
                    currentValues: stepForm.getFieldsValue(),
                    values: valuesRef.current,
                    ref:
                      // 不加这个判断的话，StepsForm.StepForm 都必须要用 forwardRef 包裹
                      ((_item$props$children = item.props.children) === null ||
                      _item$props$children === void 0
                        ? void 0
                        : (_item$props$children$ = _item$props$children.type) === null ||
                          _item$props$children$ === void 0
                        ? void 0
                        : _item$props$children$.$$typeof) === Symbol.for('react.forward_ref')
                        ? activeContentRef
                        : null,
                  });
                },
              ),
          );
        }),
      ),
    ),
    Children.map(children, function (item, index) {
      if (index === current && !item.props.virtual)
        return /*#__PURE__*/ React.createElement(
          'div',
          {
            className: 'szzj-antd-step-forms-footer',
          },
          btns,
        );
    }),
  );
};
export default /*#__PURE__*/ forwardRef(StepsForm);
